package icu.sehnen.wallpaper.controller;


import icu.sehnen.common.result.CommonResult;
import icu.sehnen.wallpaper.entity.Wallpaper;
import icu.sehnen.wallpaper.service.IWallpaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author icu.sehnen
 * @since 2021-04-26
 */
@RestController
@RequestMapping("/wallpaper")
public class WallpaperController {

    @Autowired
    IWallpaperService wallpaperService;

    @GetMapping("/list")
    public CommonResult findAll(){
        List<Wallpaper> wallpaperModelList= wallpaperService.list();
        return CommonResult.success(wallpaperModelList);

    }
    @PostMapping("/update")
    public  CommonResult update(Wallpaper wallpaper){
        wallpaperService.updateById(wallpaper);
        return CommonResult.success();
    }
    @PostMapping("/delete/{id}")
    public  CommonResult delete(@PathVariable Long id){
        boolean b = wallpaperService.removeById(id);
        if(b){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
    @GetMapping("/find/{id}")
    public CommonResult find(@PathVariable Long id){
        Wallpaper byId = wallpaperService.getById(id);
        return CommonResult.success(byId);
    }
    @PostMapping("/add")
    public CommonResult add(Wallpaper wallpaper){
        boolean save = wallpaperService.save(wallpaper);
        if(save){
            return  CommonResult.success();
        }
        return CommonResult.failed();
    }


}
